#!/usr/bin/perl -w

# This script is used to dump the all province data of china 
# Author : RainX
use DBI;

my $sourceDir;
$sourceDir  = "D:/databases/train_ticket/orig";

# get the file list

opendir(TDIR, $sourceDir);
my @lists;
my $f;
while($f = readdir(TDIR))
{
    next if $f eq ".";
    next if $f eq "..";
    push(@lists, $f);
}
closedir(TDIR);

my $dbh = DBI->connect("dbi:SQLite:dbname=/databases/train_ticket/tickets","","");

# for each it
foreach my $pFile (@lists)
{
    my $tmpTxt = getAll($sourceDir."/".$pFile);
    $tmpTxt =~s/.* <span class=redb>([^<]*).*/\1/g; 
    # print $sourceDir."/".$pFile."\n";
    #print $province."\n";
    chomp($tmpTxt);
    print $tmpTxt."\n";
    $dbh->do("replace into province (province_name) values ('$tmpTxt')");
}
$dbh->disconnect();

# get all content of file
sub getAll
{
    my ($fileName) = @_;
    open (CUTEFILE, "<$fileName");
    my @all = <CUTEFILE>;
    close(CUTEFILE);
    return join("", @all);
}

